﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Diagnostics;
using System.Runtime.CompilerServices;
using System.Text;

namespace AppDemo.ViewModels
{
    public class MainViewModel : INotifyPropertyChanged
    {
        public enum CurrentView { speakers, sessions, infos, recherche };

        public CurrentView _current;
        public CurrentView Current
        {
            get { return _current; }
            set
            {
                _current = value;
                RaisePropertyChanged("Current");
                UpdateView();
            }
        }

        private string _title = "speakers";
        public string Title
        {
            get { return _title; }
            set
            {
                _title = value;
                RaisePropertyChanged("Title");
            }
        }

        private int _index;
        public int Index
        {
            get { return _index; }
            set
            {
                _index = value;
                RaisePropertyChanged("Index");
            }
        }

        private bool _isSpeaker = true;
        public bool IsSpeaker
        {
            get { return _isSpeaker; }
            set
            {
                _isSpeaker = value;
                RaisePropertyChanged("IsSpeaker");
            }
        }

        private bool _isSessions;
        public bool IsSessions
        {
            get { return _isSessions; }
            set
            {
                _isSessions = value;
                RaisePropertyChanged("IsSessions");
            }
        }

        private bool _isInfos;
        public bool IsInfos
        {
            get { return _isInfos; }
            set
            {
                _isInfos = value;
                RaisePropertyChanged("IsInfos");
            }
        }

        private bool _isRecherche;
        public bool IsRecherche
        {
            get { return _isRecherche; }
            set
            {
                _isRecherche = value;
                RaisePropertyChanged("IsRecherche");
            }
        }

        public MainViewModel()
        {

        }

        void UpdateView()
        {

            //#if WINDOWS_APP
            //            if (!rootFrame.Navigate(typeof(HubPage)))
            //#endif
            //#if WINDOWS_PHONE_APP
            //                if (!rootFrame.Navigate(typeof(WindowsPhoneStartPage)))
            //#endif
            switch (Current)
            {
                case CurrentView.speakers:
                    Index = 0;
                    Title = "speakers";
                    IsSpeaker = true;
                    IsSessions = false;
                    IsInfos = false;
                    IsRecherche = false;
                    break;
                case CurrentView.sessions:
                    Index = 1;
                    Title = "sessions";
                    IsSpeaker = false;
                    IsSessions = true;
                    IsInfos = false;
                    IsRecherche = false;
                    break;
                case CurrentView.infos:
                    Index = 2;
                    Title = "infos";
                    IsSpeaker = false;
                    IsSessions = false;
                    IsInfos = true;
                    IsRecherche = false;
                    break;
                case CurrentView.recherche:
                    Index = 3;
                    Title = "recherche";
                    IsSpeaker = false;
                    IsSessions = false;
                    IsInfos = false;
                    IsRecherche = true;
                    break;
            }
        }

        public event PropertyChangedEventHandler PropertyChanged;
        void RaisePropertyChanged([CallerMemberName] string propertyName = "")
        {
            var handler = PropertyChanged;
            if (handler != null)
            {
                try
                {
                    handler(this, new PropertyChangedEventArgs(propertyName));
                }
                catch (Exception ex)
                {
                    Debug.WriteLine("Error raising property {0}: {1}", propertyName, ex.Message);
                }
            }
        }
    }
}
